//
//  WKMeVM.m
//  WuKongBase
//
//  Created by tt on 2020/6/9.
//

#import "WKMeVM.h"
#import "WKTableSectionUtil.h"
#import "WKMeItemCell.h"
#import "WKMePushSettingVC.h"
#import "WKCommonSettingVC.h"
#import "WKLanguageVC.h"
#import "WKMeItem.h"
@implementation WKMeVM

- (instancetype)init
{
    self = [super init];
    if (self) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            [self registerItems];
        });
    }
    return self;
}

- (void)registerItems {
    // 多语言
//        [[WKApp shared] setMethod:@"me.lang" handler:^id _Nullable(id  _Nonnull param) {
//            BOOL supportDarkMode = NO;
//            if (@available(iOS 13.0, *)) {
//                supportDarkMode = YES;
//            }
//            NSString *darkDesc = LLang(@"打开");
//            if([WKApp shared].config.darkModeWithSystem) {
//                darkDesc = LLang(@"跟随系统");
//            }else {
//                darkDesc = WKApp.shared.config.style == WKSystemStyleDark?LLang(@"打开"):LLang(@"关闭");
//            }
//
//            return  @{
////                @"height":WKSectionHeight,
//                @"items":@[
//                        @{
//                            @"class":WKLabelItemModel.class,
//                            @"label":LLang(@"语言"),
//                            @"onClick":^{
//                                WKLanguageVC *vc = [WKLanguageVC new];
//                                [[WKNavigationManager shared] pushViewController:vc animated:YES];
//                            }
//                        },
//                ],
//            };
//        } category:WKPOINT_CATEGORY_ME sort:70000];
}

- (NSArray<NSDictionary *> *)tableSectionMaps {
    NSArray<WKMeItem*> *itemModels = [[WKApp shared] invokes:WKPOINT_CATEGORY_ME param:nil];
    if(!itemModels || itemModels.count<=0) {
        return @[];
    }
    NSMutableArray *items = [NSMutableArray array];
    WKMeItem *preMeItem;
    BOOL showBottomLine = NO;
    
    for (WKMeItem *meItem in itemModels) {
//        NSLog(@"name=%@; height=%.2f", meItem.title, meItem.sectionHeight);
        if ([meItem.title isEqualToString:LLang(@"我的收藏")] || [meItem.title isEqualToString:LLang(@"通知和声音")] || [meItem.title isEqualToString:LLang(@"隐私和安全")]) {
            showBottomLine = YES;
        } else {
            showBottomLine = NO;
        }
        NSLog(@"name=%@; height=%.2f;showBottomLine=%d", meItem.title, meItem.sectionHeight, showBottomLine);
       [items addObject:@{
           @"height":@(meItem.sectionHeight + (preMeItem?preMeItem.nextSectionHeight:0)),
            @"items":@[@{
                           @"class":WKMeItemModel.class,
                           @"title":meItem.title?:@"",
                           @"value": meItem.value?:@"",
                           @"icon": meItem.icon,
                           @"bottomLeftSpace":@(0.0f),
                           @"showBottomLine":@(showBottomLine),
                           @"showTopLine":@(NO),
                           @"onClick":^(BOOL on){
                               if(meItem.onClick) {
                                   meItem.onClick();
                               }
                           }
                       }]
       }];
        preMeItem = meItem;
        
    }
    return items;
}

-(UIImage*) imageName:(NSString*)name {
    return [WKApp.shared loadImage:name moduleID:@"WuKongBase"];
//    return [[WKResource shared] resourceForImage:name podName:@"WuKongBase_images"];
}

@end

